package com.blue.gateway.paycore.wxpay.pay;

import com.blue.gateway.common.Request;
import com.blue.gateway.config.BaseChannelConfig;
import com.blue.gateway.dto.Result;
import com.blue.gateway.dto.ResultWrapper;
import com.blue.gateway.enums.PayChannelEnum;
import com.blue.gateway.utils.BigDecimalUtil;
import com.blue.gateway.annotation.Channel;
import com.blue.gateway.common.request.PayRequest;
import com.blue.gateway.config.WxConfig;
import com.blue.gateway.paycore.AbstractBaseChannelService;
import com.blue.gateway.enums.ResultCodeEnum;
import com.blue.gateway.enums.ServiceChannelEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xiaoyiming
 * @date 2020/5/3 19:15
 * @depiction 微信支付接口
 * 统一下单api:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1
 */
@Slf4j
@Channel(PayChannel = PayChannelEnum.WX, ServiceChannel = ServiceChannelEnum.PAY)
public class WxPayService extends AbstractBaseChannelService {

    @Autowired
    private WxConfig wxConfig;

    @Override
    public Result validate(Request request) {
        PayRequest payRequest = (PayRequest) request;
        if (StringUtils.isBlank(payRequest.getNotifyUrl())) {
            return ResultWrapper.fail(ResultCodeEnum.NOTIFY_URL_IS_NULL);
        }
        if (StringUtils.isBlank(payRequest.getOutTradeNo())) {
            return ResultWrapper.fail(ResultCodeEnum.OUT_TRADE_NO_IS_NULL);
        }
        if (StringUtils.isBlank(payRequest.getSubject())) {
            return ResultWrapper.fail(ResultCodeEnum.SUBJECT_IS_NULL);
        }
        if (BigDecimalUtil.ltZeroOrNull(payRequest.getTotalAmount())) {
            return ResultWrapper.fail(ResultCodeEnum.TOTAL_AMOUNT_IS_NULL);
        }
        return ResultWrapper.success();
    }


    @Override
    public BaseChannelConfig getConfig(Request request) {
        return wxConfig;
    }

    @Override
    public String generateParams(Request request, BaseChannelConfig channelConfig) {
        return null;
    }

    @Override
    public String execute(String requestParams, BaseChannelConfig channelConfig) {
        return null;
    }

    @Override
    public Result analysisResult(String executeResult) {
        return null;
    }

}
